import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('172.16.220.184', 8000))
key = 0x55
while True:
    try:
        with open('message.txt', 'r', encoding='utf-8') as f:
            content = f.read()
        content_bytes = content.encode('utf-8')
        encrypted_content = bytes([byte ^ key for byte in content_bytes])
        client.send(encrypted_content)
        encrypted_response = client.recv(1024)
        decrypted_response = bytes([byte ^ key for byte in encrypted_response])
        response_message = decrypted_response.decode('utf-8')
        print(f'服务端消息: {response_message}')
        choice = input('是否继续发送消息 (y/n): ')
        if choice.lower() != 'y':
            break
    except FileNotFoundError:
        print('未找到 message.txt 文件，请创建该文件并写入内容。')
        break
    except UnicodeDecodeError:
        print('文件编码格式不兼容，请确保文件以 utf-8 编码保存。')
client.close()